/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Current;

import java.io.Serializable;

/**
 * @author Fork
 */
public class Economy implements Serializable, Cloneable {

    private Integer totalMiners;
    private Integer goldPerMiner;
    private Integer minerGoldPerTurn;
    private Integer fortGoldPerTurn;
    private Integer totalGoldPerturn;
    private Integer dailyIncome;

    public Economy(UnitTraining ut, ProeficiencyPoints pt, StructureUpgrades st, ClassDT cls) {

        this.totalMiners = ut.getNumMiners();
        this.goldPerMiner = st.getGoldPerMiner();
        this.minerGoldPerTurn = calcMinerGoldPerTurn(ut, pt, st, cls);
        this.fortGoldPerTurn = st.getFortGoldPerTurn();
        this.totalGoldPerturn = calcTotalGoldPerTurn(ut, pt, st, cls);
        this.dailyIncome = this.totalGoldPerturn * 48;
    }

    Integer calcMinerGoldPerTurn(UnitTraining ut, ProeficiencyPoints pt, StructureUpgrades st, ClassDT cls) {
        Integer aux;
        Double multiplier;
        Double result;

        multiplier = 1 + ((double) pt.getWealth() + cls.wealthBonus()) / 100;
        aux = ut.getNumMiners() * st.getGoldPerMiner();

        result = aux * multiplier;

        return result.intValue();
    }

    Integer calcFortGoldPerTurn(ProeficiencyPoints pt, StructureUpgrades st, ClassDT cls) {
        Integer aux;
        Double multiplier;
        Double result;

        multiplier = 1 + ((double) pt.getWealth() + cls.wealthBonus()) / 100;
        aux = st.getFortGoldPerTurn();

        result = aux * multiplier;

        return result.intValue();
    }

    Integer calcTotalGoldPerTurn(UnitTraining ut, ProeficiencyPoints pt, StructureUpgrades st, ClassDT cls) {
        return calcFortGoldPerTurn(pt, st, cls) + calcMinerGoldPerTurn(ut, pt, st, cls);
    }

    public void refreshEconomy(UnitTraining ut, ProeficiencyPoints pt, StructureUpgrades st, ClassDT cls) {
        setTotalMiners(ut.getNumMiners());
        setGoldPerMiner(st.getGoldPerMiner());
        setMinerGoldPerTurn(calcMinerGoldPerTurn(ut, pt, st, cls));
        setFortGoldPerTurn(st.getFortGoldPerTurn());
        setTotalGoldPerturn(calcTotalGoldPerTurn(ut, pt, st, cls));
        setDailyIncome(this.totalGoldPerturn * 48);
    }

    //Daily Income info handling
    public Integer getDailyIncome() {
        return dailyIncome;
    }

    void setDailyIncome(int dailyIncome) {
        this.dailyIncome = dailyIncome;
    }

    //Fort Gold info handling
    public Integer getFortGoldPerTurn() {
        return fortGoldPerTurn;
    }

    void setFortGoldPerTurn(int fortGoldPerTurn) {
        this.fortGoldPerTurn = fortGoldPerTurn;
    }

    //Gold Per Miner Info handling
    public Integer getGoldPerMiner() {
        return goldPerMiner;
    }

    void setGoldPerMiner(int goldPerMiner) {
        this.goldPerMiner = goldPerMiner;
    }

    //Miner Gold per Turn info Handling
    public Integer getMinerGoldPerTurn() {
        return minerGoldPerTurn;
    }

    void setMinerGoldPerTurn(int minerGoldPerTurn) {
        this.minerGoldPerTurn = minerGoldPerTurn;
    }

    //Total Gold per Turn
    public Integer getTotalGoldPerTurn() {
        return totalGoldPerturn;
    }

    void setTotalGoldPerturn(int totalGoldPerturn) {
        this.totalGoldPerturn = totalGoldPerturn;
    }

    //Total Miners info handling
    public Integer getTotalMiners() {
        return totalMiners;
    }

    void setTotalMiners(int totalMiners) {
        this.totalMiners = totalMiners;
    }

    //Gold per eight hours info handling
    public Integer getGoldPer8Hours() {
        return this.totalGoldPerturn * 16;
    }
}
